<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * HITI Web Develop
 *
 * @package     HITI Web Dev
 * @category    Controllers
 * @see 		News
 * @author      PHUOCNGUYEN - HITI Dev Team
 * @copyright   Copyright (c) 2013, HITI Corp
 */

class News extends CI_Controller {
	var $header;
	var $footer;
	var $limit = 11;

	public function __construct()
	{
		parent::__construct();
		$this->load->model('hiti_common_model', 'hiti', true);
		$this->hiti->hiti_init();
		$this->load->model('news_model', 'news', true);
		$this->header = $this->hiti->header_templ();
		$this->footer = $this->hiti->footer_templ();
		$this->load->model('product_model', 'pro', true);
		//$this->load->model('home_model', 'home', true);
	
	}

	public function index()
	{
		$method =& get_instance();
		$info = $this->news->category($GLOBALS['cfg']['tintuc_catid']);//them
        $num = $this->news->show($info['id'], '', true);//them
		$home = array(
			
			'info' => $info,//them
			'page_list' => page_list($num, $this->limit),//them
			'method' => $method,
			'news' => $this->news->show($info['id'], $this->limit),//them
			//'news' => $this->hiti->show($info['id'], $this->limit),//them
			'categories' => $this->news->categories(),
			//'tinnb'=>$this->home->tinhot() //them
		);
		$GLOBALS['cfg']['site_title'] = $GLOBALS['cfg']['site_title'].' - Tin tức';
		/*
		* Hien thi
		*/
		$this->load->view('header', $this->header);
		$this->load->view('news/index', $home);
		$this->load->view('footer', $this->footer);
	}

	public function category($id)
	{
		$info = $this->news->category($id);
		$num = $this->news->show($info['id'], '', true);
		$home = array(
			'news' => $this->news->show($info['id'], $this->limit),
			'info' => $info,
			'page_list' => page_list($num, $this->limit)
		);
		$GLOBALS['cfg']['site_title'] = $GLOBALS['cfg']['site_title'].' - '.$info['name'];
		/*
		* Hien thi
		*/
		$this->load->view('header', $this->header);
		$this->load->view('news/category', $home);
		$this->load->view('footer', $this->footer);
	}

	public function view($id)
	{
		$info = $this->news->info($id);
		if (!$info['id'])
		{
			redirect(site_url());
		}
		$info['info'] = str_replace('../../../upload', 'upload', $info['info']);
		$info['info'] = str_replace('../../upload', 'upload', $info['info']);
		$info['info'] = str_replace('../upload', 'upload', $info['info']);
		$info['info'] = preg_replace('/\<img(.*)src=\"(.*)\"(.*) \/>/i', "<a class=\"prettyPhoto\" href=\"$2\" rel=\"prettyPhoto[gallery]\"><img$1src=\"$2\"$3 class=\"thumb_big\" /></a>", $info['info']);
		$root0_id = $info['cat'];
		$root0_name = get_data('article_categories', 'id = '.$root0_id, 'name_vn');
		$root0_key = get_data('article_categories', 'id = '.$root0_id, 'keyword');
		$root1_id = get_data('article_categories', 'id = "'.$root0_id.'"', 'parent');
		$root1_key = '';
		$root1_name = '';
		$root2_id = '';
		$root2_key = '';
		$root2_name = '';
		$root3_key = '';
		$root3_name = '';
		if ($root1_id)
		{
			$root_id = $root1_id;
			$root1_name = get_data('article_categories', 'id = '.$root1_id, 'name_vn');
			$root1_key = get_data('article_categories', 'id = '.$root1_id, 'keyword');
			$root2_id = get_data('article_categories', 'id = '.$root1_id, 'parent');
			if ($root2_id)
			{
				$root_id = $root2_id;
				$root2_name = get_data('article_categories', 'id = '.$root2_id, 'name_vn');
				$root2_key = get_data('article_categories', 'id = '.$root2_id, 'keyword');
				$root3_id = get_data('article_categories', 'id = '.$root2_id, 'parent');
				if ($root3_id)
				{
					$root_id = $root2_id;
					$root3_name = get_data('article_categories', 'id = '.$root3_id, 'name_vn');
					$root3_key = get_data('article_categories', 'id = '.$root3_id, 'keyword');
				}
			}
		}
		$home = array(
			'info' => $info,
			'root1_id' => $root1_id,
			'root1_key' => $root1_key,
			'root1_name' => $root1_name,
			'root2_id' => $root2_id,
			'root2_key' => $root2_key,
			'root2_name' => $root2_name,
			'root2_id' => $root2_id,
			'root3_key' => $root3_key,
			'root3_name' => $root3_name,
			'root0_id' => $root0_id,
			'root0_key' => $root0_key,
			'root0_name' => $root0_name,
			'list_view' => $this->news->show($info['cat'], 5, false, 'view'),
			'list_hot' => $this->pro->show(6, false, '', '', 'hot'),
		);
		$GLOBALS['cfg']['site_title'] = $info['name'];
		if ($info['des']) $GLOBALS['cfg']['site_des'] = $info['des'];
		if ($this->input->cookie('view_article'.$info['id'], true) != 1)
		{
			setcookie('view_article'.$info['id'], 1, time() + COOKIE_TIME, '/');
			$this->news->upview($info['id']);
		}
		/*
		* Hien thi
		*/
		$this->load->view('header', $this->header);
		$this->load->view('news/view', $home);
		$this->load->view('footer', $this->footer);
	}

	public function category_news($cat)
	{
		return $this->news->show($cat, 5);
	}

}

/* End of file news.php */
/* Location: ./application/controllers/news.php */